#include "AppGlobal.h"

s32 updateTransEntityByRecvData(TransEntity *transEntity, Transmit8583Data *transmitData)
{
    s8 utfMsg[256] = {0};
    s32 revlen = ZERO;

    if (transEntity == NULL || transmitData == NULL)
    {
        return CONTROL_ERR_PARAM;
    }

    if (libTransIsQrCodePay(transmitData->mTransType))
    {
        memset(utfMsg, 0x00, sizeof(utfMsg));
        revlen = sdk8583GetField(&transmitData->mRecvBag, 58, (u8 *) utfMsg, sizeof(utfMsg));
        if (revlen >= 0)
        {
            snprintf(transEntity->mTransDetails.mOutOrder, sizeof(transEntity->mTransDetails.mOutOrder), "%s", utfMsg);
        }

        memset(utfMsg, 0x00, sizeof(utfMsg));
        revlen = sdk8583GetField(&transmitData->mRecvBag, 46, (u8 *) utfMsg, sizeof(utfMsg));
        if (revlen >= 0)
        {
            snprintf(transEntity->mTransDetails.mPaymentInfo, sizeof(transEntity->mTransDetails.mPaymentInfo), "%s", utfMsg);
        }
    }
    return SDK_OK;
}

void initTrans()
{
    platform_trans_set_update_trans_entity_func((UpdateTransEntityFunc) updateTransEntityByRecvData);
}